package com.sg.service;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTUtil;
import com.sg.controller.UserController;
import com.sg.entity.UserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class LoginService {

    @Resource
    private UserInfoService userInfoService;

    public UserInfo getLoginYh(HttpServletRequest request){
        String token = request.getHeader(UserController.AUTH_HEADER_NAME);
        JWT jwt = JWTUtil.parseToken(token);
        Object uid = jwt.getPayload().getClaim("uid");
       return userInfoService.getById(Integer.parseInt(uid.toString()));
    }
}
